package com.northwind.controller;

import com.northwind.entity.Video;
import com.northwind.service.VideoService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.util.HashMap;

@Controller
@RequestMapping("video")
public class VideoController {
    @Resource
    VideoService videoService;

    @ResponseBody
    @RequestMapping("queryAllPage")
    public HashMap<String, Object> queryAllPage(Integer page, Integer rows) {
        return videoService.queryAllPage(page, rows);
    }

    @ResponseBody
    @RequestMapping("updateStatus")
    public void updateStatus(Video video){
        System.out.println("要进行修改用户的信息:"+video);
        videoService.update(video);
    }

    @ResponseBody
    @RequestMapping("edit")
    public String edit(Video video,String oper) {
        String id = null;
        if (oper.equals("add")){
            System.out.println("要添加的视频为:"+video);
            id = videoService.add(video);

        }
        if (oper.equals("del")){
            System.out.println("删除的用户为:"+video);
            videoService.delete(video);
        }
        if(oper.equals("edit")){
            System.out.println("修改的用户为"+video);
            videoService.update(video);
        }
        return id;
    }

    @ResponseBody
    @RequestMapping("uploadVideo")
    public HashMap<String, Object> fileUpload (MultipartFile videoPath,String id){
        System.out.println("文件名:"+videoPath.getOriginalFilename());
        System.out.println("文件大小:"+videoPath.getSize());
        HashMap<String, Object> map = videoService.fileUploadByAliyun(videoPath,id);
        return map;
    }
}
